package com.eryos.android.cigarettecounter.io;

import android.content.SharedPreferences;

/**
 * Project :  CigaretteCounter
 * Author :   Olivier Combe 
 * URL :      http://eryos.fr/CigaretteCounter/
 *
 * Copyright (C) 2011 - Olivier Combe 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */

public class Preferences {

	public final static String PREF_BOX_SIZE 		= "boxSize";
	public final static String PREF_BOX_PRICE 		= "boxPrice";
	public final static String PREF_CIGARETTE_PRICE = "cigarettePrice";

	private int boxSize = -1;		// Quantity of cigarettes in a box
	private float boxPrice = -1f;	// Price of the box
	private float cigarettePrice = 0f;//boxPrice / boxSize;

	SharedPreferences settings;
	
	public Preferences(SharedPreferences _settings){
		settings = _settings;
	}
	/**
	* Store static param into preferences file
	*/
	public void storeParamToFile( ){

		SharedPreferences.Editor editor = settings.edit();

		editor.putInt(PREF_BOX_SIZE, boxSize);
		editor.putFloat(PREF_BOX_PRICE, boxPrice);
		editor.putFloat(PREF_CIGARETTE_PRICE, cigarettePrice);
		editor.commit();
	}

	/**
	* Read static param from preferences file
	*/
	public void readParamFromFile(){
		try {

			boxSize  = settings.getInt(PREF_BOX_SIZE, -1);
			boxPrice = settings.getFloat(PREF_BOX_PRICE, -1f);
			cigarettePrice = settings.getFloat(PREF_CIGARETTE_PRICE, 0);

		} catch(Exception e){
			e.printStackTrace();
			boxSize = -1;
			boxPrice = -1f;
			cigarettePrice = 0;
		}
	}
	public int getBoxSize() {
		return boxSize;
	}
	public void setBoxSize(int _boxSize) {
		this.boxSize = _boxSize;
	}
	public float getBoxPrice() {
		return boxPrice;
	}
	public void setBoxPrice(float _boxPrice) {
		this.boxPrice = _boxPrice;
	}
	public float getCigarettePrice() {
		return cigarettePrice;
	}
	public void setCigarettePrice(float cigarettePrice) {
		this.cigarettePrice = cigarettePrice;
	}


	
}
